import React, { PureComponent } from "react";

class Child extends PureComponent {
  // 只要父组件重新渲染了，子组件也必定会重新渲染, 除非使用PureComponent，或者在shouldComponentUpdate返回false
  // 父组件render -> 子组件render -> 子组件componentDidMount -> 父组件componentDidMount
  render() {
    console.log("child render");
    return <div>child组件 - {this.props.count}</div>;
  }

  componentDidMount() {
    console.log("child mounted");
  }

  // 被废弃了
  // 组件将要接收props
  UNSAFE_componentWillReceiveProps() {
    console.log("UNSAFE_componentWillReceiveProps");
  }

  // shouldComponentUpdate(nextProps) {
  //   return nextProps.count !== this.props.count;
  // }

  UNSAFE_componentWillUpdate() {
    console.log("child componentWillUpdate");
  }

  componentDidUpdate() {
    console.log("child componentDidUpdate");
  }
}

export default Child;
